package com.kaigejava.juc.lock.ReadWriteLock;

/**
 * @author kaigejava
 * 读写锁演示入口
 */
public class ReadWriteLockDemo {
    public static void main(String[] args) {
        //无锁的 不适用
        //Screen screen = new Screen();
        //独占式的 不适用
    //    ScreenReentrant screen = new ScreenReentrant();
        //使用读写锁模式的
        ScreenReadWrite screen = new ScreenReadWrite();
        final  String carNo = "G505";
        //车站工作人员更新
        String [] carMsg = new String []{"检票中","晚点5分钟","候车中"};
        for(int i = 0;i<3;i++){
            final int msgIdex = i;
            new Thread(()->{
                screen.writeMsg(""+carNo,carMsg[msgIdex]);
            }).start();
        }
        //乘客获取车次信息
        for(int i = 1;i<4;i++){
            new Thread(()->{
                screen.ReadMsg(""+carNo);
            }).start();
        }
    }
}
